const express = require("express");
const app = express();

// 配置静态文件
app.use(express.static("./public"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

// 给home一个接口
app.use("/home/list", (req, res) => {
  res.send({
    name: "张三",
    info: [1, 2, 3, 4, 5],
  });
});

// 给login一个post接口
const loginRouter = express.Router();
loginRouter.post("/", (req, res) => {
  if (req.body.userName === "张三" && req.body.password === "123456")
    res.send({ ok: 1 });
  else res.send({ ok: 0 });
});
app.use("/login", loginRouter);

app.use("/", (req, res) => {
  res.status(404).send("404 Not Found");
});

app.listen(3000, () => {
  console.log("3000 Port");
});
